var t = getApp();

Page({
    data: {
        selected: "0",
        display: 1,
        pagesize: 1,
        wait_used: [],
        overdue: [],
        used: [],
        underway: [],
        loading: !1,
        allLoaded: !1,
        goload: !0,
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        love_name: "",
        usable: 0,
        index: "",
        trading_money: 0,
        balanceLang: "余额"
    },
    onLoad: function(t) {
        this.getUsable(), this.getNetData("");
    },
    onReady: function() {},
    onShow: function() {
        try {
            var t = wx.getStorageSync("yz_basic_info");
            t && (t = t.balance || "余额", this.setData({
                balanceLang: t
            }), wx.setNavigationBarTitle({
                title: t
            }));
        } catch (t) {}
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    getData: function() {
        var e = this, a = t.getNetAddresss("plugin.love.Frontend.Modules.Love.Controllers.recharge.page");
        t._getNetWork({
            url: a,
            success: function(t) {
                var a = t.data;
                1 === a.result && e.setData({
                    value: a.data.member_usable,
                    every_value: a.data.recharge_rate_money,
                    transform_value: a.data.recharge_rate_love
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    onChange: function(t) {
        var e;
        0 == t.detail.index ? (e = t.detail.index = "", this.setData({
            selected: ""
        })) : (e = t.detail.index -= 1, this.setData({
            index: e
        })), this.getNetData(e);
    },
    getNetData: function(e) {
        var a = this, n = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : "", o = t.getNetAddresss("plugin.love.Frontend.Modules.Trading.Controllers.trading.trading-center");
        o += "&status=" + e, o += "&own=" + n, o += "&page=1", console.log(o, "struel"), 
        t._getNetWork({
            url: o,
            success: function(t) {
                if (1 == t.data.result) {
                    var n = t.data.data;
                    a.setData({
                        total_page: t.data.data.total
                    }), "" == e && "string" == typeof e ? a.setData({
                        underway: [],
                        done: [],
                        own: [],
                        wait_used: n
                    }) : 1 == e ? a.setData({
                        wait_used: [],
                        underway: [],
                        own: [],
                        done: n
                    }) : 2 == e ? a.setData({
                        wait_used: [],
                        underway: [],
                        done: [],
                        own: n
                    }) : 0 == e && a.setData({
                        wait_used: [],
                        done: [],
                        own: [],
                        underway: n
                    });
                } else wx.showToast({
                    title: t.data.msg,
                    icon: "none",
                    image: "",
                    duration: 1500,
                    mask: !1
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    revoke: function(e) {
        var a = this, n = e.currentTarget.dataset.id, o = t.getNetAddresss("plugin.love.Frontend.Modules.Trading.Controllers.trading.revoke");
        o += "&id=" + n, t._getNetWork({
            url: o,
            success: function(t) {
                1 == t.data.result ? (wx.showToast({
                    title: t.data.msg,
                    icon: "none"
                }), setTimeout(function() {
                    "0" == a.data.selected && a.getNetData(a.data.index);
                }, 1e3)) : wx.showToast({
                    title: t.data.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    purchase: function(e) {
        var a = this, n = e.currentTarget.dataset.id, o = e.currentTarget.dataset.amount;
        wx.showModal({
            content: "点击确定将扣除".concat((Number(this.data.trading_money) * Number(o)).toFixed(2)).concat(this.data.balanceLang, ",操作不可逆转，请咨询核对是否确认兑换"),
            success: function(e) {
                if (console.log(e), e.confirm) {
                    var o = t.getNetAddresss("plugin.love.Frontend.Modules.Trading.Controllers.trading.purchase");
                    o += "&id=" + n, t._getNetWork({
                        url: o,
                        success: function(t) {
                            1 == t.data.result ? (wx.showToast({
                                title: t.data.msg,
                                icon: "none"
                            }), setTimeout(function() {
                                "0" == a.data.selected ? a.getNetData("") : a.getNetData("0");
                            }, 1e3)) : wx.showToast({
                                title: t.data.msg,
                                icon: "none"
                            });
                        },
                        fail: function(t) {
                            console.log(t);
                        }
                    });
                }
            },
            fail: function(t) {}
        });
    },
    getUsable: function() {
        var e = this, a = t.getNetAddresss("plugin.love.Frontend.Controllers.page.index");
        t._getNetWork({
            url: a,
            success: function(t) {
                1 === t.data.result ? (e.setData({
                    love_name: t.data.data.love_name,
                    trading_money: t.data.data.trading_set.trading_money
                }), wx.setNavigationBarTitle({
                    title: t.data.data.love_name ? t.data.data.love_name + "交易中心" : "交易中心"
                })) : wx.showToast({
                    title: t.data.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    }
});